﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Threading.Thread;
using static System.Console;

namespace NotesUnitTest
{
    public class MyTestAsync
    {
        public static void Go()
        {
            int result = 0;
            for (int i = 0; i < 3; i++)
            {
                Task<int> t = GetResultAsync();
                t.Wait();
                result += t.Result;
            }
            WriteLine(result);
        }

        static async Task<int> GetResultAsync()
        {
            var result = 0;
            for (int i = 0; i < 5; i++)
            {
                await Task.Delay(3);
                result++;
                WriteLine($"当前线程id： {CurrentThread.ManagedThreadId}，i：{i}");
            }

            return result;
        }

        static void TaskDemo()
        {
            string str = "dsassa";
            Task<int> t = Task.Run(() => GetSum(str));
        }


        static int GetSum(string str)
        {
            Func<string, int> func = x => x.Length;
            return func(str);
        }
    }
}
